package com.ruoyi.common.utils.bean;

import java.util.HashMap;
import java.util.Map;
import com.ruoyi.common.utils.bean.SpringBeanUtil;


/**
 * @author xumh
 * @title: Factory
 * @projectName ruoyi
 * @description: TODO
 * @date 2024/12/1215:22
 */
public class Factory {

    private static Map<String, Object> instance = new HashMap();
    private static final String instance_synchronize = "__synchronize__";

    public Factory() {
    }

    public static <T> T instance(Class<T> entityClass) {
        T existObj = (T) instance.get(entityClass.getName());
        if (existObj != null) {
            return existObj;
        } else {
            String var2 = "__synchronize__";
            synchronized("__synchronize__") {
                T obj = (T) instance.get(entityClass.getName());
                if (obj != null) {
                    return obj;
                } else {
                    obj = SpringBeanUtil.getBeanByType(entityClass);
                    instance.put(entityClass.getName(), obj);
                    return obj;
                }
            }
        }
    }
}
